package io.renren.modules.workmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.workmanagement.dao.QuestionBankCourseRelDao;
import io.renren.modules.workmanagement.entity.QuestionBankCourseRelEntity;
import io.renren.modules.workmanagement.service.QuestionBankCourseRelService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("questionBankCourseRelService")
public class QuestionBankCourseRelServiceImpl extends ServiceImpl<QuestionBankCourseRelDao, QuestionBankCourseRelEntity> implements QuestionBankCourseRelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<QuestionBankCourseRelEntity> page = this.page(
                new Query<QuestionBankCourseRelEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    public QuestionBankCourseRelEntity getByBankId(Long bankId) {
        return this.lambdaQuery().eq(QuestionBankCourseRelEntity::getBankId, bankId).one();
    }

    @Override
    public void removeByBankIds(List<String> bankIds) {
        this.lambdaUpdate().in(QuestionBankCourseRelEntity::getBankId, bankIds).remove();
    }

    @Override
    public List<QuestionBankCourseRelEntity> listByBankIds(List<Long> bankIds) {
        return this.lambdaQuery().in(QuestionBankCourseRelEntity::getBankId, bankIds).list();
    }

    @Override
    public List<QuestionBankCourseRelEntity> listByCourseId(Long courseId) {
        return this.lambdaQuery().eq(QuestionBankCourseRelEntity::getCourseId, courseId).list();
    }

    @Override
    public List<QuestionBankCourseRelEntity> listByCourseIds(List<Long> courseIds) {
        return this.lambdaQuery().in(QuestionBankCourseRelEntity::getCourseId, courseIds).list();
    }

}
